package config

import (
	"fmt"
	"github.com/spf13/viper"
)

var GormConfig *gormConfig

type gormConfig struct {
	Host         string `mapstructure:"host"`
	User         string `mapstructure:"user"`
	Password     string `mapstructure:"password"`
	DB           string `mapstructure:"dbname"`
	Port         int    `mapstructure:"port"`
	MaxOpenConns int    `mapstructure:"max_open_conns"`
	MaxIdleConns int    `mapstructure:"max_idle_conns"`
}

func init() {
	GormConfig = new(gormConfig)
	// 将读取的配置信息保存至全局变量Conf
	if err := viper.Sub("mysql").Unmarshal(GormConfig); err != nil {
		panic(fmt.Errorf("unmarshal gorm conf failed, err:%s \n", err))
	}

}
